package com.bestcem.xm.om.service.impl;

import com.bestcem.xm.common.core.domain.web.ServiceResult;
import com.bestcem.xm.common.core.enums.ResourceErrorCodeEnum;
import com.bestcem.xm.om.dao.OmIndustryDao;
import com.bestcem.xm.om.dao.UserBookingDao;
import com.bestcem.xm.om.entity.OmIndustry;
import com.bestcem.xm.om.entity.UserBooking;
import com.bestcem.xm.om.service.UserBookingService;
import com.bestcem.xm.om.service.dto.UpdateUserBookingsDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 描述信息
 *
 * @author xuan.yang <xuan.yang@idiaoyan.com>
 * @version v1.0
 * @date 2022/2/22 13:53
 */
@Slf4j
@Service
public class UserBookingServiceImpl implements UserBookingService {
    @Resource
    private UserBookingDao userBookingDao;
    @Resource
    private OmIndustryDao omIndustryDao;

    @Override
    public ServiceResult<Void> updateByOrgId(UpdateUserBookingsDTO updateUserBookingsDTO) {
        OmIndustry omIndustry = omIndustryDao.findById(updateUserBookingsDTO.getIndustryId());
        if (Objects.isNull(omIndustry)) {
            return ServiceResult.fail(ResourceErrorCodeEnum.NOT_FOUND, "行业信息不存在");
        }
        UserBooking userBooking = new UserBooking();
        userBooking.setOrgId(updateUserBookingsDTO.getOrgId());
        userBooking.setIndustryId(updateUserBookingsDTO.getIndustryId());
        userBooking.setIndustryName(omIndustry.getName());
        userBooking.setCompanyName(updateUserBookingsDTO.getCompanyName());
        userBooking.setContact(updateUserBookingsDTO.getPhone());
        userBooking.setEmail(updateUserBookingsDTO.getEmail());
        userBookingDao.updateByOrgId(userBooking);
        return ServiceResult.success();
    }
}
